package org.jeecg.modules.sjlx.service.impl;

import org.apache.shiro.SecurityUtils;
import org.jeecg.common.system.vo.LoginUser;
import org.jeecg.modules.sjlx.entity.CsXxSjlx;
import org.jeecg.modules.sjlx.mapper.CsXxSjlxMapper;
import org.jeecg.modules.sjlx.service.ICsXxSjlxService;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import java.util.Date;

/**
 * @Description: 数据类型
 * @Author: jeecg-boot
 * @Date:   2023-10-28
 * @Version: V1.0
 */
@Service
public class CsXxSjlxServiceImpl extends ServiceImpl<CsXxSjlxMapper, CsXxSjlx> implements ICsXxSjlxService {

    /**
     * 初始化数据类型枚举类型
     */
    enum IntiSjlxEnum {
        djkp ("单据开票","djkp"),
        jkkp ("接口开票","jkkp"),
        drkp ("导入开票","drkp"),
        sm ("扫码开票","sm"),
        sg ("手工开票","sg");
        private final String desc;//描述
        private final String value;//值
        IntiSjlxEnum(String desc, String value) {
            this.desc = desc;
            this.value = value;
        }

        public String getDesc() {
            return desc;
        }

        public String getValue() {
            return value;
        }

    }

    /**
     * 在新增加账套租户时初试化系统内置的数据类型
     * @param tenantId
     */
   public void initSjxl(int tenantId){
       for(IntiSjlxEnum sjlxEnum : IntiSjlxEnum.values()){
           CsXxSjlx csXxSjlx=new CsXxSjlx();
           csXxSjlx.setCcode(sjlxEnum.getValue());
           csXxSjlx.setCname(sjlxEnum.getDesc());
           csXxSjlx.setCdesc("系统内置请误删除");
           csXxSjlx.setTenantId(tenantId);
           LoginUser user=(LoginUser) SecurityUtils.getSubject().getPrincipal();
           if(user!=null){
               csXxSjlx.setCreateBy(user.getUsername());
               csXxSjlx.setSysOrgCode(user.getOrgCode());
           }
           csXxSjlx.setCreateTime(new Date());
           this.save(csXxSjlx);
       }
    }
}
